package com.ruoyi.project.system.controller;

import java.util.Date;
import java.util.List;

import cn.hutool.core.lang.ObjectId;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.SnowflakeUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.MatchInformation;
import com.ruoyi.project.system.service.IMatchInformationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 竞赛信息Controller
 * 
 * @author student
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/system/information")
public class MatchInformationController extends BaseController
{
    @Resource
    private IMatchInformationService matchInformationService;

    /**
     * 查询竞赛信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(MatchInformation matchInformation)
    {
        startPage();
        List<MatchInformation> list = matchInformationService.selectMatchInformationList(matchInformation);
        return getDataTable(list);
    }

    /**
     * 导出竞赛信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "竞赛信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MatchInformation matchInformation)
    {
        List<MatchInformation> list = matchInformationService.selectMatchInformationList(matchInformation);
        ExcelUtil<MatchInformation> util = new ExcelUtil<MatchInformation>(MatchInformation.class);
        return util.exportExcel(list, "竞赛信息数据");
    }

    /**
     * 获取竞赛信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(matchInformationService.selectMatchInformationById(id));
    }

    /**
     * 新增竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:add')")
    @Log(title = "竞赛信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MatchInformation matchInformation)
    {
        matchInformation.setId(SnowflakeUtil.nextId());
        matchInformation.setCreateBy(getUsername());
        matchInformation.setCreateDate(new Date());
        return toAjax(matchInformationService.insertMatchInformation(matchInformation));
    }

    /**
     * 修改竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:edit')")
    @Log(title = "竞赛信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MatchInformation matchInformation)
    {
        return toAjax(matchInformationService.updateMatchInformation(matchInformation));
    }

    /**
     * 删除竞赛信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:remove')")
    @Log(title = "竞赛信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(matchInformationService.deleteMatchInformationByIds(ids));
    }
}
